import { _decorator, Component, Node, Label, director } from 'cc';
import { SSS_AudioManager } from 'db://assets/Script/Manager/SSS_AudioManager';
import { ColorBlock_GameData } from '../Data/ColorBlock_GameData';
import { SSS_Consts } from 'db://assets/Script/Data/SSS_Consts';

const { ccclass, property } = _decorator;

@ccclass('ColorBlock_GamePanel')
export default class ColorBlock_GamePanel extends Component {
    static Instance: ColorBlock_GamePanel;
    @property(Node)
    Button_back: Node | null = null;
    @property(Node)
    Button_refresh: Node | null = null;
    @property(Label)
    Label_score: Label | null = null;
    @property(Label)
    Label_highScore: Label | null = null;

    onLoad() {
        ColorBlock_GamePanel.Instance = this;
    }
    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();
    }
    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }
    Refresh() {
        this.Label_score.string = `${ColorBlock_GameData.Get_score()}`;
        this.Label_highScore.string = `${ColorBlock_GameData.Get_high_score()}`;
    }
    AddListener() {
        this.Button_back.on(Node.EventType.TOUCH_END, this.On_Button_back, this);
        this.Button_refresh.on(Node.EventType.TOUCH_END, this.On_Button_refresh, this);
    }
    RemoveListener() {
        this.Button_back.off(Node.EventType.TOUCH_END, this.On_Button_back, this);
        this.Button_refresh.off(Node.EventType.TOUCH_END, this.On_Button_refresh, this);
    }
    On_Button_back() {
        director.loadScene(SSS_Consts.SceneName.MainScene);

        SSS_AudioManager.PlayButtonAudio();
    }

    On_Button_refresh() {
        director.loadScene(SSS_Consts.SceneName.ColorBlock_Game_Scene);

        SSS_AudioManager.PlayButtonAudio();
    }
}

// /** 调试 */
window["ColorBlock_GamePanel"] = ColorBlock_GamePanel;